package com.lagou.edu.server;


import java.util.HashMap;
import java.util.Map;

/**
 * @author 胡益文
 * @since 2021/10/13 14:27
 */
public class Mapper {
    volatile Map<String,MappedHost> hosts = new HashMap<>();

    public Mapper(Map<String,MappedHost> hosts) {
        this.hosts = hosts;
    }

    protected abstract static class MapElement<T> {

        public final String name;
        public final T object;

        public MapElement(String name, T object) {
            this.name = name;
            this.object = object;
        }
    }

    protected static final class MappedHost extends MapElement<Host> {
        public Map<String,MappedContext> contexts;
        public MappedHost(String name, Host host,Map<String,MappedContext> contexts) {
            super(name, host);
            this.contexts = contexts;
        }

    }

    protected static final class MappedContext extends MapElement<Context> {
        public volatile Map<String,MappedWrapper> wrappers;
        public MappedContext(String name,Context context, Map<String,MappedWrapper> wrappers) {
            super(name, context);
            this.wrappers = wrappers;
        }
    }

    protected static class MappedWrapper extends MapElement<Wrapper> {
        public MappedWrapper(String name, Wrapper wrapper) {
            super(name, wrapper);
        }
    }


}
